package com.fangcang.mongodb.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
import org.springframework.data.mongodb.gridfs.GridFsTemplate;

import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;

//@Configuration
public class MongoDbConfiguration extends AbstractMongoConfiguration{

	@Value("${spring.data.mongodb.uri}")
	private String mongodbUri;

	@Bean
	public MongoTemplate mongoTemplate(MongoDbFactory mongoDbFactory) {
		return new MongoTemplate(mongoDbFactory);
	}
	
	@Bean
	public MongoDbFactory mongoDbFactory() {
		return new SimpleMongoDbFactory(new MongoClientURI(mongodbUri));
	}
	
	@Bean
	public GridFsTemplate gridFsTemplate(MongoDbFactory mongoDbFactory) throws Exception {
		return new GridFsTemplate(mongoDbFactory,  mappingMongoConverter());
	}

	@Override
	public MongoClient mongoClient() {
		return null;
	}

	@Override
	protected String getDatabaseName() {
		return null;
	}
	
	
	
}
